package com.youlu.campus.website.controller;

import com.youlu.campus.common.base.QResult;
import com.youlu.campus.website.entity.CampanyTopic;
import com.youlu.campus.website.entity.CampanyTopicPageQuery;
import com.youlu.campus.website.service.CampanyTopicService;
import org.springframework.data.domain.Page;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 公司主题控制层
 *
 * @author su
 * @date 2025/08/25
 */
@RestController
@RequestMapping("/website/campany/topic")
public class CampanyTopicController {

    @Resource
    private CampanyTopicService campanyTopicService;

    /**
     * 新增公司主题
     *
     * @param campanyTopic 公司主题实体
     * @return QResult<CampanyTopic>
     */
    @PostMapping("/save")
    public QResult<CampanyTopic> saveCampanyTopic(@RequestBody CampanyTopic campanyTopic) {
        return QResult.success(campanyTopicService.save(campanyTopic));
    }

    /**
     * 根据 ID 删除公司主题
     *
     * @param campanyTopic 公司主题 ID
     * @return QResult<Boolean>
     */
    @PostMapping("/delete")
    public QResult<Boolean> deleteCampanyTopicById(@RequestBody CampanyTopic campanyTopic) {
        Assert.hasText(campanyTopic.getId(), "公司主题 ID 不能为空");
        return QResult.success(campanyTopicService.delete(campanyTopic.getId()));
    }


    /**
     * 根据 ID 查询公司主题详情
     *
     * @param id 公司主题 ID
     * @return QResult<CampanyTopic>
     */
    @GetMapping("/info")
    public QResult<CampanyTopic> getCampanyTopicById(@RequestParam String id) {
        return QResult.success(campanyTopicService.findById(id));
    }

    /**
     * 分页查询公司主题列表
     *
     * @param pageQuery
     * @return QResult<Page < CampanyTopic>>
     */
    @PostMapping("/find-page")
    public QResult<Page<CampanyTopic>> getCampanyTopicPage(@RequestBody CampanyTopicPageQuery pageQuery) {
        return QResult.success(campanyTopicService.findByPage(pageQuery));
    }
}